﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace robotics_ex_1_3
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: <Input File>");
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("The input file is missing!");
            }

            string[] inputLines = File.ReadAllLines(args[0]);

            Polygon robotPolygon = new Polygon(Convert.ToUInt32(inputLines[0]), inputLines[1]);
            robotPolygon.Edges.Sort(delegate(Line line1, Line line2)
                                    {
                                        return line1.Angle.CompareTo(line2.Angle);
                                    });

            Polygon roomPolygon = new Polygon(Convert.ToUInt32(inputLines[2]), inputLines[3]);

            Room room = new Room(roomPolygon);

            List<Point> freeSpacePointsList = room.calcFreeSpace(robotPolygon);

            Console.WriteLine("Number of vertices - " + freeSpacePointsList.Count);
            foreach (var point in freeSpacePointsList)
            {
                Console.WriteLine(point.ToString());
            }
            /*       Point a1=new Point(0,0); 
                   Point  a2 = new Point(2, 0);
                   Point b1 = new Point(1, 0);
                   Point b2 = new Point(1, 3);
                   Point c1 = new Point(2, 1);
                   Point c2 = new Point(0, 1);
                   Point d1=new Point(0,4);
                   Point  d2 = new Point(0, 0); */
                     /*Point a1 = new Point(0, 3);
                     Point a2 = new Point(3, 0);
                     Point b1 = new Point(0, 1);
                     Point b2 = new Point(3, 4);
                     Point c1 = new Point(1, 4);
                     Point c2 = new Point(4, 1);
                     Point d1 = new Point(1, 0);
                     Point d2 = new Point(4, 3); 
            Line[] vertice_list = new Line[4];
            vertice_list[0] = new Line(a1, a2);
            vertice_list[1] = new Line(b1, b2);
            vertice_list[2] = new Line(c1, c2);
            vertice_list[3] = new Line(d1, d2);
            List<Point> freeSpacePointsList = NewPolygonFinder.extract_polygon(vertice_list);

            Console.WriteLine("Number of vertices - " + freeSpacePointsList.Count);
            foreach (var point in freeSpacePointsList)
            {
                Console.WriteLine(string.Format("\t({0},{1})", point.X, point.Y));
            }*/
        }
    }
}
